#include <iostream>
#include <string.h>

using namespace std;

int T, res, w, n;
int d[30], t[30], v[30];
bool marked[30], rmarked[30];

void attempt(int ind, int time, int gold)
{
	if (time > T) return;

	if (ind == n)
	{
		if (res < gold)
		{
			res = gold;
			for (int i = 0; i < n; i++) rmarked[i] = marked[i];
		}

		return;
	}

	marked[ind] = true;
	
	attempt(ind+1, time+t[ind], gold+v[ind]);
	
	marked[ind] = false;

	attempt(ind+1, time, gold);
}

int main()
{
	int ntest = 0;	

	while (cin >> T >> w)
	{
		if (ntest > 0) cout << endl;
		ntest++;		

		cin >> n;
		for (int i = 0; i < n; i++) 
		{
			cin >> d[i] >> v[i];
			t[i] = 3*w*d[i];
		}

		res = -1000000000;
		memset(marked, false, sizeof(marked));
		attempt(0, 0, 0);

		cout << res << endl;

		int count = 0;
		for (int i = 0; i < n; i++)
			if (rmarked[i]) count++;
		cout << count << endl;

		for (int i = 0; i < n; i++)
			if (rmarked[i]) cout << d[i] << " " << v[i] << endl;
	}

	return 0;
}
